import user from '../../../utils/user'
import { inputchange } from '../../../utils/util'
import { recharge } from '../../../api/app'
const app = getApp()
Page({
    data: {
        num: '',
        productType: 'MassRecharge'
    },
    onLoad (options) {

    },
    inputchange(event){
        console.log(event.detail.value,'event',this,'充值了多少钱')
        // event.detail.value = event.detail.value.replace(/[^\d]/g,'')
        event.detail.value = event.detail.value.replace(/\.\w{1,}/g,'')
        inputchange(event,this)
    },
    onRecharge(){
        if(this.data.num < 1){
            app.toast('不可小于1元')
            return
        }
        recharge({
            useWay: this.data.productType,
            description: '账户充值',
            mchid: user.mchid,
            amount: {
                total: this.data.num
            },
            payer: {
                openid: user.openid
            }
        }).then(res=>{
            res.package = res.packageValue
            wx.requestPayment(res).then(()=>{
                wx.navigateTo({
                    url: '/pages/success/success?title=充值成功&content=您可以稍后查看您的账户余额&opinion=0&back=2'
                })
            },err=>{
                console.log(err)
            })
        })
    },
})